<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Spring MVC响应</title>
    <!--js文件也会被前端控制器拦截，注意要配置前端控制器放行静态资源-->
    <!--src路径的斜杠要和springmvc.xml中的配置一致-->
    <script src="../js/jquery-3.4.1.min.js"></script>
    <script>
        $(function () {
            $("#btn").click(function () {
                $.ajax({
                    //json格式
                    url: "../user/ajax",
                    contentType: "application/json;charset=utf-8",
                    data: '{"name":"发送","age":88}',
                    dataType: "json",
                    type: "post",
                    success: function (responseData) {
                        //服务器响应的json数据
                        var json = responseData;
                        //alert(json);
                        var s = "";
                        for (var k in json) {
                            s += k + "=" + json[k] + "<br>";
                        }
                        $("#res").html(s);
                    }
                });
            });
        });
    </script>
</head>
<body>
<h2>1.返回为字符串</h2>
<a href="../user/string">测试返回</a>
<hr>

<h2>2.返回为void</h2>
<a href="../user/void">测试默认转发（页面404，注意看控制台打印信息）</a><br>
<a href="../user/void2">测试手动指定转发</a>
<hr>

<h2>3.返回ModelAndView对象</h2>
<a href="../user/mav">测试返回</a>
<hr>

<h2>4.使用forward和redirect关键字实现页面跳转</h2>
<a href="../user/far">测试返回</a>
<hr>

<h2>5.ajax异步响应json数据</h2>
<button id="btn">测试返回</button>
<div id="res"></div>
<hr>
</body>
</html>
